Skip to content
This repository has been archived by the owner on Apr 25, 2021. It is now read-only.

add JDK 9 support #143

Merged
merged 6 commits into from Mar 10, 2017
Merged

add JDK 9 support #143

merged 6 commits into from Mar 10, 2017

Conversation

eed3si9n
Copy link
Member

This copies https://github.com/retronym/java9-rt-export into this repository.

Next it improves the version detection script using sed.
When Java 9 is detected it uses java9-rt-export to evaluate the sbt's global base directory, and it copies the rt.jar off to the side, and starts sbt with -Dscala.ext.dirs flag as described in sbt/sbt#2951.

For Windows, it uses a bit more primitive method of detecting the Java version since sed is not available by default.

${java_args[@]} \
-jar "$rtexport" \
"${java9_rt}"
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will copy rt.jar only once. However, jdk 9 might be updated over time. People may select different versions for debugging reasons, or may flip from OpenJDK to Oracle's JDK, to IBM's JVM. That may cause unexpected behavior or crashes. Probably rt.jar should be copied on each startup; alternatively, the full version string could be dumped to a text file and matched upon startup, so that if it differs the rt.jar file is extracted again.

vlog "[process_args] java_version = '$java_version'"
rtexport=$(rt_export_file)
sbt_global_dir=$("$java_cmd" ${JAVA_OPTS} ${SBT_OPTS:-$default_sbt_opts} ${java_args[@]} \
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to move this out to copyRt so I can use this script from Java 1.6 and 1.7.

@dwijnand
Copy link
Member

dwijnand commented Mar 6, 2017

@eed3si9n you mentioned you were seeing a 1.8 java.version in the system property. Could you show what you did? I'm not seeing it:

$ java -version
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+158)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+158, mixed mode)

$ echo 'public class T { public static void main(String... args) { System.out.println(System.getProperty("java.version")); } }' > T.java

$ javac T.java

$ java T
9-ea

@dwijnand
Copy link
Member

dwijnand commented Mar 6, 2017

Using the Scala 2.12.1 REPL:

scala> sys.props.toSeq filter (_._1 matches "java.*version") foreach println
(java.specification.version,9)
(java.vm.specification.version,9)
(java.runtime.version,9-ea+158)
(java.version,9-ea)
(java.vm.version,9-ea+158)
(java.class.version,53.0)

@cunei
Copy link

cunei commented Mar 6, 2017

The string used for versioning should include vendor, patch level, and all the details that may uniquely identify a given JVM release. Here are a few suggestions: http://stackoverflow.com/a/5103166
Also:

java -XshowSettings:properties -version

@eed3si9n
Copy link
Member Author

eed3si9n commented Mar 7, 2017

I did something along the lines of

            if (destination.equals("--rt-ext-dir")) {
                System.out.println(System.getProperty("java.version"));

                String v = System.getProperty("java.version");
                Path rtExtDir = Paths.get(globalBase, "java9-rt-ext-" + v);
                System.out.println(rtExtDir.toString());
                System.exit(0);
            }

compiled it using Java 8, and ran it on JDK 9, and I get this:

$ java -version
java version "9-ea"
Java(TM) SE Runtime Environment (build 9-ea+156)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+156, mixed mode)
$ java -jar ~/work/sbt-modules/sbt-launcher-package/target/universal/stage/bin/java9-rt-export.jar --rt-ext-dir
1.8.0_91
/Users/xxx/.sbt/0.13/java9-rt-ext-1.8.0_91

@eed3si9n
Copy link
Member Author

eed3si9n commented Mar 7, 2017

Here's a WIP commit - a2ee22e
What am I doing wrong here?

@dwijnand
Copy link
Member

dwijnand commented Mar 7, 2017

FWIW, rebasing that change on @retronym's original doesn't show what you're seeing:

diff --git a/src/main/java/io/github/retronym/java9rtexport/Export.java b/src/main/java/io/github/retronym/java9rtexport/Export.java
index 5591dde..e5c2b41 100644
--- a/src/main/java/io/github/retronym/java9rtexport/Export.java
+++ b/src/main/java/io/github/retronym/java9rtexport/Export.java
@@ -10,6 +10,8 @@ import java.util.Map;
 public class Export {
     public static void main(String[] args) {
         try {
+            final String v = System.getProperty("java.version");
+            System.out.println("java.version = " + v);
             FileSystem fileSystem = FileSystems.getFileSystem(URI.create("jrt:/"));
             Path path = fileSystem.getPath("/modules");
             String destination = args[0];
10:58:32 $ jenv local 1.8

10:58:37 $ sbt clean package
[info] Loading global plugins from /Users/dnw/.dotfiles/.sbt/0.13/plugins
[info] Loading project definition from /d/java9-rt-export/project
[info] Set current project to java9-rt-export (in build file:/d/java9-rt-export/)
[success] Total time: 0 s, completed 07-Mar-2017 10:58:50
[info] Updating {file:/d/java9-rt-export/}java9-rt-export...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 2 Java sources to /d/java9-rt-export/target/classes...
[info] Packaging /d/java9-rt-export/target/java9-rt-export-0.1-SNAPSHOT.jar ...
[info] Done packaging.
[success] Total time: 1 s, completed 07-Mar-2017 10:58:51

10:58:51 $ jenv local 9-ea

10:58:55 $ java -jar target/java9-rt-export-0.1-SNAPSHOT.jar rt.jar
java.version = 9-ea

@dwijnand
Copy link
Member

dwijnand commented Mar 7, 2017

I can't reproduce what you're seeing. Using a2ee22e on your wip/jdk9_branch:

11:20:22 $ jenv local 1.8

11:20:26 $ sbt -Dsbt.build.version=1.0.0 java9rtexport/clean java9rtexport/package
[info] Loading global plugins from /Users/dnw/.dotfiles/.sbt/0.13/plugins
[info] Loading project definition from /d/sbt-launcher-package/project/project
[info] Loading project definition from /d/sbt-launcher-package/project
[info] Set current project to sbt-launcher-packaging (in build file:/d/sbt-launcher-package/)
[success] Total time: 0 s, completed 07-Mar-2017 11:20:40
[info] Updating {file:/d/sbt-launcher-package/}java9rtexport...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 2 Java sources to /d/sbt-launcher-package/java9-rt-export/target/classes...
[info] Packaging /d/sbt-launcher-package/java9-rt-export/target/java9-rt-export-0.1-SNAPSHOT.jar ...
[info] Done packaging.
[success] Total time: 1 s, completed 07-Mar-2017 11:20:41

11:20:42 $ jenv local 9-ea

11:20:48 $ java -jar java9-rt-export/target/java9-rt-export-0.1-SNAPSHOT.jar --rt-ext-dir
/Users/dnw/.sbt/0.13/java9-rt-ext-9-ea

Something's up with your setup maybe.

@eed3si9n
Copy link
Member Author

eed3si9n commented Mar 7, 2017

I finally figured out the mystery. When I was running the following:

$ java -jar ~/work/sbt-modules/sbt-launcher-package/target/universal/stage/bin/java9-rt-export.jar --rt-ext-dir

jenv was picking up .java-version file located in ~/work/sbt-modules/sbt-launcher-package, even though my current directory was somewhere completely different. This is why my java -version and java -jar ... behaved differently.

@eed3si9n
Copy link
Member Author

eed3si9n commented Mar 8, 2017

So now that --rt-ext-dir problem is solved, this PR is ready for another round of review?

@dwijnand
Copy link
Member

dwijnand commented Mar 9, 2017

Vendor properties and values on my 9-ea installation (using jshell):

15:14:41 $ JENV_VERSION=9-ea jshell
|  Welcome to JShell -- Version 9-ea
|  For an introduction type: /help intro

jshell> System.getProperties().entrySet().stream().collect(Collectors.toList()).stream().sorted((x, y) -> x.getKey().toString().compareTo(y.getKey().toString())).filter(kv -> kv.getKey().toString().contains("vendor")).map(kv -> String.format("%-45s %s", kv.getKey(), kv.getValue())).forEach(System.out::println)
java.specification.vendor                     Oracle Corporation
java.vendor                                   Oracle Corporation
java.vendor.url                               http://java.oracle.com/
java.vendor.url.bug                           http://bugreport.java.com/bugreport/
java.vm.specification.vendor                  Oracle Corporation
java.vm.vendor                                Oracle Corporation

@cunei
Copy link

cunei commented Mar 9, 2017

I would say a concatenation (with spaces/special characters remapped/removed) of these three, for the directory name:

    java.vm.name = Java HotSpot(TM) 64-Bit Server VM
    java.vm.specification.vendor = Oracle Corporation
    java.version = 1.8.0_121

@eed3si9n
Copy link
Member Author

eed3si9n commented Mar 9, 2017

For compiler bridge sbt currently just uses java.version as postfix. Maybe we can add java.vendor but I don't think we need to worry about java.vm.name.

@cunei
Copy link

cunei commented Mar 10, 2017

@eed3si9n All right, LGTM.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants